Make ATTError an extensible struct#201
Conversation
| public struct ATTError: RawRepresentable, Equatable, Hashable, Error { | ||
| public typealias RawValue = UInt8 | ||
|
|
||
| enum Code: UInt8 { |
There was a problem hiding this comment.
Can you remove the Code enum and change that to static var cases.
There was a problem hiding this comment.
To confirm, do you want the numeric codes represented as static var cases, or the actual error cases changed to static var?
// Existing PR state:
public static let invalidHandle = ATTError(code: .invalidHandle)
// Potential change:
public static var invalidHandle = ATTError(code: 0x01)! // ! is known safe in this caseThere was a problem hiding this comment.
@colemancda Happy to make changes here, just looking for some clarification
There was a problem hiding this comment.
@dpogueproton Sorry for delay. This is what I am looking for.
public static var invalidHandle: ATTError { ATTError(rawValue: 0x01) }
If this type is not a finite number of known cases, then making it a RawRepresentable struct with a non-failable initializer is the proper API design to follow.
d980833 to
d06a666
Compare
|
Updated with the requested changes. Note that this is technically now an API-breaking change, because the non-failable initializer means ATTError can no longer be used in guard/if statements that check for nilness. |
Issue
Fixes #200.
What does this PR Do?
Converts
ATTErrorfrom an enum to a struct to allow for extending with additional application-specific error codes.ATTError(rawValue: 0)returns nil because 0x00 is the success code.All the pre-defined errors are set up so they return a non-Optional ATTError, and this should be API compatible with all existing code.
Where should the reviewer start?
ATTError.swift